package cn.wsalix.observable.service.impl;

import java.util.Observable;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.wsalix.msg.entity.Message;
import cn.wsalix.msg.form.MessageForm;
import cn.wsalix.msg.service.MessRapportService;
import cn.wsalix.msg.service.MessageService;
import cn.wsalix.msg.service.PushService;
import cn.wsalix.observable.service.SendService;
import cn.wsalix.user.service.MineService;

@Service("sendService")
public class SendServiceImpl extends Observable implements SendService {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private PushService pushService;
	@Autowired
	private MessageService messageService;
	@Autowired
	private MessRapportService messRapportService;

	@Autowired
	private MineService myProductService;
	private Message message;

	@PostConstruct
	public void init() {
		logger.info("==========init");
		addObserver(myProductService);
		addObserver(pushService);
		addObserver(messRapportService);
		addObserver(messageService);
	}

	@PreDestroy
	public void destroy() {
		logger.info("==========destroy");
	}

	@Transactional
	@Override
	public Message sendMess(MessageForm form) {
		setChanged();
		notifyObservers(form);
		return message;
	}

	public Message getMessage() {
		return message;
	}

	public void setMessage(Message message) {
		this.message = message;
	}

}
